<?php

class Model_Page_Community extends RL_Model2 implements ArrayAccess
{
	private $acl_data;
	private $aa;
	private $img_storage;

	private $_data = array();

	public function initialize (array $cfg)
	{
		foreach ($cfg as $k=>$v) $this->$k = $v;
	} // end of __construct

	public function getUrl ()
	{
		if (isset($this->_data['url'])) return $this->_data['url'];
		return $this->acl_data['community_url'];
	} // end of method getUrl
	public function getMod ()
	{
		if (isset($this->_data['mod'])) return $this->_data['mod'];
		return $this->acl_data['mod'];
	} // end of method getMod
	public function getTitle ()
	{
		if (isset($this->_data['title'])) return $this->_data['title'];
		return $this->acl_data['title'];
	} // end of method getTitle
	public function getLogoImage ()
	{
		if (isset($this->_data['logo_image'])) return $this->_data['logo_image'];
		return $this->_data['logo_image']
			= $this->getImageStorage()->Get($this->getLogoImageOid());
	} // end of method getLogoImage
	public function getLogoImageOid ()
	{
		if (isset($this->_data['logo_image_oid'])) return $this->_data['logo_image_oid'];
		return $this->acl_data['logo_image_oid'];
	} // end of method getLogoImageOid
	public function getBackgroundImage ()
	{
		if (isset($this->_data['background_image'])) return $this->_data['background_image'];
		return $this->_data['background_image']
			= $this->getImageStorage()->Get($this->getBackgroundImageOid());
	} // end of method getBackgroundImage
	public function getBackgroundImageOid ()
	{
		if (isset($this->_data['background_image_oid'])) return $this->_data['background_image_oid'];
		return $this->acl_data['background_image_oid'];
	} // end of method getBackgroundImageOid
	public function getAcl ()
	{
		if (isset($this->_data['acl'])) return $this->_data['acl'];
		return $this->aa->getAcl($this->acl_data['comity_oid']);
	} // end of method getAcl
	public function getTdiCount ()
	{
		if (isset($this->_data['tdi_count'])) return $this->_data['tdi_count'];
		return count($this->acl_data['tdi_list']);
	} // end of method getTdiCount
	public function getOid ()
	{
		if (isset($this->_data['comity_oid'])) return $this->_data['comity_oid'];
		return $this->acl_data['comity_oid'];
	} // end of method getOid
	public function getMembersCount ()
	{
		if (isset($this->_data['members_count'])) return $this->_data['members_count'];
		return $this->_data['members_count']
			= $this->aa->getMembersCount($this->getOid());
	} // end of method getOid

	public function offsetGet ($k)
	{
		if (array_key_exists($k, $this->_data)) return $this->_data[$k];
		$mn = 'get'.str_replace('_', '', $k);
		if (method_exists($this,$mn)) return $this->$mn();
		return NULL;
	} // end of method getOffset
	public function offsetSet ($k, $v)
	{
		$this->_data[$k] = $v;
	} // end of method setOffset
	public function offsetExists ($k)
	{
		$mn = 'get'.str_replace($k, '_', '');
		return method_exists($this,$mn) || array_key_exists($k, $this->_data);
	} // end of method offsetExists
	public function offsetUnset ($k)
	{
		unset($this->_data[$k]);
	} // end of method offsetUnset

	public function __toString ()
	{
		return 'Model_Page_User';
	} // end of method __toString

	private function getImageStorage ()
	{
		if (!isset($this->img_storage)) {
			$this->mm->rh->UseClass('stores_ImageStorage');
			$this->img_storage = new ImageStorage( $this->store );
		}
		return $this->img_storage;
	} // end of method getImageObj
}


